<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE HTML PUBLIC "" "">
<f:view xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:w="http://www.apusic.com/jsf/widget" xmlns:layout="http://www.apusic.com/jsf/layout"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:ajax="http://www.apusic.com/jsf/ajax"
	renderKitId="AJAX">
	<w:head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<w:stylesheet src="/css/kmp4.css" type="text/css"></w:stylesheet>
		<w:script src="/javascript/k4.js" type="text/javascript" language="UTF-8"></w:script>
	</w:head>
	<w:page title="分配角色权限">
		<w:form id="setUserRole">
			<layout:panelGrid columns="3" width="400">
				<layout:cell colspan="3">
					<legend>已分配权限</legend>
					<w:tree id="resourceTree" height="300" autoScroll="true" rootVisible="false"/>
				</layout:cell>
				<layout:cell colspan="3" align="center">
					<layout:panelGrid columns="2">
						<layout:cell>
							<w:button label="保存" id="saveUserRole" immediate="true"
								onclick="return showConfirm('请确定保存吗？')" image="/images/save.gif"/>
						</layout:cell>
						<layout:cell>
							<w:button label="重置" onclick="javascript:window.location.reload();" immediate="true"
								alwaysSubmit="false" image="/images/clear.gif"/>
						</layout:cell>
					</layout:panelGrid>
				</layout:cell>
			</layout:panelGrid>
		</w:form>
		<layout:window id="showSuccess" jsvar="showSuccess" title="保存成功" show="false" height="150"
			width="300" x="100" y="150">保存成功</layout:window>
	</w:page>
	<script>
	//<![CDATA[
	//选择用户
	function selectUser(selectObj){
		//alert('value is:'+value);
		//alert(value.value);
		//alert(value.options[value.selectedIndex].text);
		var value=selectObj.value;
		var text=selectObj.options[selectObj.selectedIndex].text;
		var roleUsers=document.getElementById("setUserRole:usersOfRole");
		//alert(roleUsers);
		addValue(roleUsers,value,text);
	}
	//删除用户
	function removeUser(objSelect,value){
		//alert(objSelect);
		for (var i = 0; i < objSelect.options.length; i++) {    
            if (objSelect.options[i].value == value) {    
                objSelect.remove(i);
                break;
            }
        }
	}
	function addValue(selctObject,value,text){
		var isDup=false;
		for(var i=0;i<selctObject.length;i++){
		var opValue=selctObject.options[i].value;
		  if(opValue==value){
		       isDup=true;
		  }
		}
		if(!isDup){
		     var newValueOption=document.createElement("OPTION");
		     newValueOption.setAttribute("value",value);
		     newValueOption.text=text;
		     selctObject.options.add(newValueOption);
		}
	}
	function submitForm(){
		var roles=document.getElementById("selectedRoles");
		var roleUsers=document.getElementById("setUserRole:usersOfRole");
		var result="";
		for(var i=0;i<roleUsers.options.length;i++){
			result=roleUsers.options[i].value+','+result;
		}
		if(result.length>0){
			result=result.substring(0,result.length-1);
		}
		roles.value=result;
		return true;
	}
	//]]></script>
</f:view>